<?php
// +----------------------------------------------------------------------
// | Author: 张坤
// +----------------------------------------------------------------------
namespace Admin\Controller; 
class PhoneshopController extends AdminController { 
	public function index() {
		$map = array();
		if(isset($_GET['categoryno'])){
			$map['categoryno']   =   I('categoryno',0);
		}
		$list=M('Phoneshop')->where($map)->select();
		//转化记录集为json数据格式
		for ($i=0; $i<count($list); $i++)
		{
 			if(mb_strwidth($list[$i]['brandname'], 'utf8')>=15)
 			{
 				$list[$i]['brandname']=mb_strimwidth($list[$i]['brandname'], 0, 15, '..', 'utf8');
 			}
 			if(mb_strwidth($list[$i]['introduce'], 'utf8')>=15)
 			{
 				$list[$i]['introduce']=mb_strimwidth($list[$i]['introduce'], 0, 15, '..', 'utf8');
 			}
		}
		$this->assign("_list",$list);
		$catelist=M('Phoneindexicon')->select();
		$this->assign("_catelist",$catelist);
		$this->assign('category_id',I('get.categoryno',0));
		$this->display('index');
	} 
	/**
	 * 保存
	 */
	public function savePicShow() { 
		$res = D('Phoneshop')->update();
		if(!$res){
			$this->error(D('Phoneshop')->getError());
		}else{
			$this->success('保存成功！', U('Phoneshop/index'));
		}
	}
	/**
	 * 删除
	 */
	public function deletePicShow($id) { 
		$map ['id'] = $id;
		M("Phoneshop")->where($map)->delete();		
		$this->redirect('index');
	}
	/**
	 * 修改前
	 */
	public function editPicShow($id) {
		//当前编辑页面 
		$data = M ( 'Phoneshop' )->field ( true )->find ( $id );
		$this->assign ( 'data', $data );
		//所有信息
		$list=M('Phoneshop')->select();
		//转化记录集为json数据格式
		for ($i=0; $i<count($list); $i++)
		{
			if(mb_strwidth($list[$i]['brandname'], 'utf8')>=15)
			{
				$list[$i]['brandname']=mb_strimwidth($list[$i]['brandname'], 0, 15, '..', 'utf8');
			}
			if(mb_strwidth($list[$i]['introduce'], 'utf8')>=15)
			{
				$list[$i]['introduce']=mb_strimwidth($list[$i]['introduce'], 0, 15, '..', 'utf8');
			}
		}
		$this->assign("_list",$list);
		$catelist=M('Phoneindexicon')->select();
		$this->assign("_catelist",$catelist);
		$this->display('index');
	}
	
}
